package linkedList1;

import java.util.*;

public class LinkedListDemo {
	public static void main(String[] args) {
		LinkedList newsTitle = new LinkedList();
		NewsTitle title1 = new NewsTitle(1, "财经", "admin");
		NewsTitle title2 = new NewsTitle(2, "娱乐", "admin");
		NewsTitle title3 = new NewsTitle(3, "民生", "admin");
		newsTitle.addFirst(title1);
		newsTitle.addLast(title2);
		newsTitle.add(title3);

		// 获取新闻标题的总数
		System.out.println("新闻标题总数量是：" + newsTitle.size());

		// 逐条打印每条新闻
		for (int i = 0; i < newsTitle.size(); i++) {
			NewsTitle news = (NewsTitle) newsTitle.get(i);
			System.out.println(news.getId() + "-" + news.getNewsName() + "-" + news.getCreator());
		}

		NewsTitle first = (NewsTitle) newsTitle.getFirst();
		System.out.println("头条新闻是：" + first.getNewsName());

		NewsTitle last = (NewsTitle) newsTitle.getLast();
		System.out.println("末条新闻是：" + last.getNewsName());
		
		NewsTitle last1 = (NewsTitle) newsTitle.removeLast();
		System.out.println("删除掉的末条新闻是：" + last1.getNewsName());

		System.out.println("删除后新闻标题的总数是：" + newsTitle.size());

		System.out.println("删除后剩下的新闻分别是：");
		for (int i = 0; i < newsTitle.size(); i++) {
			NewsTitle news = (NewsTitle) newsTitle.get(i);
			System.out.println(news.getId() + "-" + news.getNewsName() + "-" + news.getCreator());
		}
	}
}
